<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>

<style>
	#edit_table {text-align:center;border:1px solid #ddd; border-width:0 0 1px 1px;}
	
	#edit_table tr,#edit_table td {height:22px; border:1px solid #ddd; border-width:1px 1px 0 0;}
</style>

<script type="text/javascript">
<!--
	function onSave(){
	    var errorMsg = "";
		if($("#userCode").val().length != 3){
			errorMsg = '<s:text name="dialog.message.tip.userCodeWrong"/>' ;
		}
		if($("#username").val().trim()=="" || $("#userCode").val().trim()=="" || $("#compName").val().trim()==""){
			errorMsg = '<s:text name="dialog.message.tip.needRequiredFields"/>' ;
		}
		
		if(errorMsg != ""){
			showErrorTip(errorMsg);
			return false;
		}
		return true;
	}
	
	function deleteTip(tipId,userId){
		window.location.href = "./UserMgr_deleteTip.do?editUserId="+userId+"&deleteTipId="+tipId;
	}
	
	function selectRole(){
		var role = $("#userRole").find("option:selected").val(); 
		updateByRole(role);
	}
	
	function updateByRole(role){
		if(role == "0"){
			$("#userCode").val("");
			$("#compName").val("");
			$("#userCode").attr("disabled","");
			$("#compName").attr("disabled","");
		}else{
			$("#userCode").val("---");
			$("#compName").val("---");
			$("#userCode").attr("disabled","disabled");
			$("#compName").attr("disabled","disabled");
		}
	}
	
	function returnTo(){
		window.location.href = "./UserMgr_search.do";
	}
	
	$(document).ready(
			
	); 
	
//-->
</script>

<s:include value="./component/tip_box.jsp"></s:include>

<s:form action="UserMgr_save" validate="false" method="post" enctype="multipart/form-data" onsubmit="return onSave()">
	<s:hidden key="user.id"/>
	<s:hidden key="user.status"/>
	<div align="left">
		<s:actionmessage cssStyle="color:#0000FF;"/>
		<s:actionerror cssStyle="color:#F00;"/>
	</div>
	<table id="edit_table" style="background-color:#F5F5F5;margin-top:1cm;" width="800" height="300" >
		<tr>
			<td align="right" style="background:#CCEEFF;" class="label_bold">
			   <s:text name="user.userRole"/><font color="red">*</font>:
			</td>
			<td align="left">
				 <s:if test="user.id != null">
				 	<s:label key="user.RoleName"></s:label>
					<s:hidden  id="userRole" name="user.userRole"></s:hidden>
				</s:if>
				<s:else>
					<s:select id="userRole" name="user.userRole" list="roles" onchange="selectRole()"/>
				</s:else>
			</td>
			<td align="right" style="background:#CCEEFF;" class="label_bold">
				<s:text name="user.userCode"/><font color="red">*</font>:
			</td>
			<td align="left">
				<s:if test="user.id != null">
					<s:label key="user.userCode"></s:label>
					<s:hidden id="userCode" name="user.userCode"></s:hidden>
				</s:if>
				<s:else>
					<s:textfield id="userCode" name="user.userCode"/>
				</s:else>
			</td>
		</tr>
		<tr>
			<td align="right" style="background:#CCEEFF;" class="label_bold">
				 <s:text name="user.username"/><font color="red">*</font>:
			</td>
			<td align="left">
				<s:if test="user.id != null">
					<s:label key="user.username"></s:label>
					<s:hidden  id="username" name="user.username"></s:hidden>
				</s:if>
				<s:else>
					<s:textfield id="username" name="user.username"/>
				</s:else>
			</td>
			<td align="right" style="background:#CCEEFF;" class="label_bold">
				<s:text name="label.password"/>:
			</td>
			<td align="left">
				<s:if test="user.id != null">
					<s:textfield name="user.password"/>
				</s:if>
			</td>
		</tr>
		<tr>
			<td align="right" style="background:#CCEEFF;" class="label_bold">
				 <s:text name="user.fax"/>:
			</td>
			<td align="left">
				<s:textfield key="user.fax"/>
			</td>
			<td align="right" style="background:#CCEEFF;">
				 <s:text name="user.tel"/>:
			</td>
			<td align="left">
				<s:textfield key="user.tel"/>
			</td>
		</tr>
		<s:if test="user.id != null && user.userRole == 0">
			<tr>
			     <td align="right" style="background:#CCEEFF;" class="label_bold">
					ICON:
				</td>
				<td colspan="3" align="left">
					<s:file key="upload" id="upload"></s:file>
				</td>
			</tr>
		</s:if>
		<tr>
			<td align="right" style="background:#CCEEFF;" class="label_bold">
				 <s:text name="user.userCompName"/><font color="red">*</font>:
			</td>
			<td colspan="3" align="left">
				 <s:if test="user.id !=null && user.userRole != 0">
				 	  <s:textfield id="compName" key="user.userCompName" size="80" readonly="true"/>
				 </s:if>
				 <s:else>
					 <s:textfield id="compName" key="user.userCompName" size="80"/>
				 </s:else>
			</td>
		</tr>
		<tr>
		     <td align="right" style="background:#CCEEFF;" class="label_bold">
				 <s:text name="user.address"/>:
			</td>
			<td colspan="3" align="left">
				<s:textfield key="user.address" size="80"/>
			</td>
		</tr>
		<tr>
		     <td align="right" style="background:#CCEEFF;" class="label_bold">
				 SOP:
			</td>
			<td colspan="3" align="left">
				<s:textarea key="user.sop" cols="60" rows="10"></s:textarea>
			</td>
		</tr>
		
		<c:if test="${ShowUserTips == true}">
			<tr>
				<td align="left" colspan="4">
						 <div id="users-contain" class="ui-widget">
							<table width="100%" id="users" class="ui-widget ui-widget-content" >
								<thead>
									<tr class="ui-widget-header ">
										<th width="20%"><s:text name="usertip.tiptype"/></th>
										<th width="75%"><s:text name="usertip.tipValue"/></th>
										<th width="5%"><s:text name="action.action"/></th>
									</tr>
								</thead>
								<tbody>
									<s:iterator value="user.userTipSet">
										<s:if test="id != null">
											<tr id="tip_<s:property value="id"/>">
												<td><s:property value="typeName"/></td>
												<td><s:property value="tipValue"/></td>
												<td><input type="button" value="<s:text name="action.delete"/>" onclick='deleteTip(<s:property value="id"/>,<s:property value="user.id"/>)'></td>
											</tr>
										</s:if>
									</s:iterator>
								</tbody>
							</table>
						</div>
				</td>
			</tr>
		</c:if>
		<tr>
			<td colspan="4" align="center">
				<s:submit key="action.save" action="UserMgr_save" cssClass="btn"/>
        		<s:reset key="action.reset" cssClass="btn"/>
			</td>
		</tr>
	</table>
	
</s:form>
